// pages/zy/zy.js
var app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_zan:false,
    name:''
  },

  phone:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.phone, //仅为示例，并非真实的电话号码
      success:function(res){
        console.log(res)
      }
    })
  },

  zan:function(e){
    console.log(e.currentTarget.id)
    var id = e.currentTarget.id
    var that=this
    wx.request({
      url: app.globalData.url +'xcx/ResouresAct',
      data: { info_id: id, act_num: 3 },
      method: "post",
      success:function(res){
        console.log(res)
        if(res.data.code==10000){
          wx.setStorageSync('zan'+id, id)
          that.setData({
            is_zan:true
          })
        }

      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var resourceid = options.id
    var phone = options.phone
   
    var wx_id=wx.getStorageSync('uid')
   
    var that=this
    wx.request({
      url: app.globalData.url +'xcx/detialresource/' + resourceid+'/'+wx_id,
      data:{

      },
      method:"get",
      success:function(res){

      if(res.data.data){
        wx.request({
          url: app.globalData.url + 'xcx/getuser/' + res.data.data.user_wx_id,
          method:'get',
          success:function(ret){
            console.log(ret);
            that.setData({
             
              name:ret.data.data.one[0].card_name,
              phone: ret.data.data.one[0].card_phone
            })
          }
        })
      }


        console.log(res)
        if (wx_id == res.data.data.user_wx_id) {
          that.setData({
            is_my: true
          })
        } else {
          that.setData({
            is_my: false
          })
        }
        that.setData({
          user_id: res.data.data.user_wx_id,
          arrlist:res.data.data,
          // phone:res.data.code,
          id: resourceid
        })
        var title = that.data.arrlist.title
        wx.setNavigationBarTitle({
          title: title
        })
      }

    })

  
    wx.request({
      url: app.globalData.url + 'xcx/ResouresAct',
      data: { info_id: resourceid, act_num: 2 },
      method: "post",
      success: function (res) {
        console.log(res)
        // if (res.data.code == 10000) {
        //   wx.showToast({
        //     title: '分享成功',
        //     icon: 'success'
        //   })
        // }
      }
    })

    var zanid = wx.getStorageSync('zan' + resourceid)
    if (zanid && zanid == resourceid){
      that.setData({is_zan:true})
    }else{
      that.setData({ is_zan: false })
    }

   
   
  },


  nav_card:function(){
    wx.navigateTo({
      url: '../dwzs/dwzs?id='+this.data.user_id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)


    }


    var title=this.data.arrlist.title
    var that=this
    return {
      title: title,
      imageUrl:'http://'+ that.data.arrlist.imgone,
       success: function (rept) {
         var id = res.target.id
         console.log(id)
         wx.request({
           url: app.globalData.url +'xcx/ResouresAct',
           data:{info_id:id,act_num:1},
           method:"post",
           success:function(res){
              console.log(res)
              if(res.data.code==10000){
                wx.showToast({
                  title: '分享成功',
                  icon:'success'
                })
              }
           }
         })
      },
    }
  }
})